function clearAndPushAll(arr, items) {
    if(arr&&arr instanceof Array&&items&&items instanceof Array){
        arr.splice(0, arr.length);
        arr.push(...items);
    }
}

function replaceWith(inArr,fromArr,compareFunc){

    if(inArr&&inArr instanceof Array&&fromArr&&fromArr instanceof Array){
        // if(inArr.length===0){
        //     clearAndPushAll(inArr,fromArr);
        // }else {
            fromArr.forEach(fromEle=>{
                let idx = inArr.findIndex(inEle=>compareFunc(inEle,fromEle));
                if(idx>=0){
                    inArr.splice(idx,1,fromEle);
                }
            })
        // }
    }
}

function keepIndentifiedSwapIn(inArr,fromArr,compareFunc){
    replaceWith(fromArr,inArr,compareFunc);
    clearAndPushAll(inArr,fromArr);
}

// // let aArr = ['aaa','bbb','ccc','ddd','eee'];
// // let aArr = ['aaa','bbb','ccc'];
// // let aArr = ['aaa'];
// let aArr = [];
// let bArr =['bbb2','eeee2'];
// //
// keepIndentifiedSwapIn(bArr,aArr,(inEle,fromEle)=>{
//     return fromEle.indexOf(inEle)>=0;
// })
// //
// console.log(bArr)

function any(arr,func){
    func("sss");

    // return arr.filter(function(ele){
    //     return func(ele)
    // }).length>0;

    return arr.filter(ele=>func(ele)).length>0;
}

let ccc ={cc:"ccc1"}
ccc.aas = function(ele){
    return this.cc===ele;
}

// any(["ssss"],ccc.aas);//错误
// any(["ssss"],ele=>ccc.aas(ele)) //正确

export {clearAndPushAll,replaceWith,keepIndentifiedSwapIn};